New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tuyapi

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tuyapi

An easy-to-use API for devices that use Tuya's cloud services (currently only supports smart plugs)

  • 2.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-50.26%
Maintainers
2
Weekly downloads
 
Created
Source

TuyAPI 🌧 🔌 XO code style

A library for communicating with devices that use the Tuya cloud network. These devices are branded under many different names, but if port 6668 is open on your device chances are this library will work with it. Currently only supports smart plugs, but it should be fairly trivial to add other types of devices.

Installation

npm install codetheweb/tuyapi

Basic Usage

const TuyaDevice = require('tuyapi');

let tuya = new TuyaDevice({
  id: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx'});

tuya.resolveIds().then(() => {  
  tuya.get().then(status => {
    console.log('Status: ' + status);

    tuya.set({set: !status}).then(result => {
      console.log('Result of setting status to ' + !status + ': ' + result);

      tuya.get().then(status => {
        console.log('New status: ' + status);
        return;
      });
    });
  });
});

This should report the current status, set the device to the opposite of what it currently is, then report the changed status.

See the setup instructions for how to find the needed parameters.

📓 Docs

See the docs.

IMPORTANT: Only one TCP connection can be in use with a device at once. If testing this, do not have the app on your phone open.

TODO

  1. Add automated tests
  2. Document details of protocol
  3. Retry when ECONNRESET is thrown

Contributors

Keywords

FAQs

Package last updated on 14 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc